package com.huiying.mapper;


import com.huiying.entity.entity.Comment;
import com.huiying.entity.vo.ParentComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: lsh
 * @Date: 2024/11/27/17:21
 * @Description: 评论数据访问接口
 */

@Mapper
public interface CommentMapper {

    // 查询父评论（没有 parent_id 的评论）
    List<ParentComment> getParentComments(Long contentId);

    // 根据一组 parentId 查询所有子评论
    List<ParentComment> getRepliesByParentIds(@Param("parentIds") List<Long> parentIds);

    // 插入评论
    @Insert("INSERT INTO comments (content, image_url, content_id, content_type, user_id, parent_id, replied_user_id, created_time) " +
            "VALUES (#{content}, #{imageUrl}, #{contentId}, #{contentType}, #{userId}, #{parentId}, #{repliedUserId}, #{createdTime})")
    void insertComment(Comment comment);

    @Select("select user_id from comments where id = #{parentId}")
    Long getRepliedUserIdByCommentId(Long parentId);

    @Delete("delete from comments where content_id = #{demandId} and content_type = #{demand}")
    void deleteByItemId(@Param("demandId") Long demandId,
                        @Param("demand") String demand);
}
